package com.ityc.mapper;

import com.ityc.pojo.Student;
import com.ityc.pojo.StudentQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {
    @Select("select count(*) from student where clazz_id = #{id}")
    Integer countByClazzId(Integer id);

    List<Student> list(StudentQueryParam studentQueryParam);

    @Insert("insert into student(name, no, gender, phone, id_card, is_college, address, degree, graduation_date, clazz_id, create_time, update_time) " +
    "values (#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree},#{graduationDate},#{clazzId},#{createTime},#{updateTime})")
    void insert(Student student);

    @Select("select id, name, no, gender, phone, id_card, is_college, address, degree, graduation_date, clazz_id, create_time, update_time from student where id = #{id} ")
    Student getById(Integer id);

    void updateById(Student student);

    void deleteByIds(List<Integer> ids);

    @Update("update student set violation_count = violation_count + 1, violation_score = violation_score + #{score},update_time = now() where id = #{id} ")
    void updateViolation(Integer id, Integer score);

    @MapKey("degree")
    List<Map<String, Object>> CountStudentDegreeData();

    @Select("select c.name cname,count(s.name) scount from clazz c left join student s on c.id = s.clazz_id group by c.name order by count(s.id) desc")
    List<Map<String, Object>> StudentCount();
}
